﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage/Main.Master" AutoEventWireup="true" CodeBehind="EmployeeManagementUpdateDelete.aspx.cs" Inherits="RestaurantManagerWebApp.Pages.UserManagement.EmployeeManagementUpdateDelete" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .auto-style12 {
            width: 110px;
        }

        .auto-style13 {
        width: 162px;
    }

        .auto-style15 {
        width: 403px;
    }

        .auto-style16 {
            width: 358px;
        }

        .auto-style17 {
            width: 239px;
        }

        .auto-style18 {
            width: 150px;
        }
    .auto-style19 {
        height: 66px;
    }
    .auto-style20 {
        width: 403px;
        height: 66px;
    }
    .auto-style21 {
        width: 84px;
        height: 31px;
    }
    .auto-style22 {
        width: 239px;
        height: 66px;
    }
    .auto-style23 {
        height: 66px;
        width: 162px;
    }
    </style>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <p style="text-align: center">
        <asp:Label ID="Label3" runat="server" Text="Update Employee Record Portal" ForeColor="Blue" Font-Bold="True" Font-Size="Larger"></asp:Label>

    </p>
    <p>
        <asp:LinkButton ID="lbHome" runat="server" PostBackUrl="~/Pages/UserManagement/ManagementHome.aspx" CausesValidation="False">Home</asp:LinkButton>
    </p>

    <div style="width: 100%; height: 300px; overflow: auto">
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="emp_id,u_id" DataSourceID="EMP_Records" HeaderStyle-BackColor="yellow" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" Width="1550px" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" Height="288px" style="margin-bottom: 0px">
            <Columns>
                <asp:BoundField DataField="id_no" HeaderText="NRIC/FIN" SortExpression="id_no">
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Top" />
                </asp:BoundField>
                <asp:BoundField DataField="emp_id" HeaderText="Employee ID" ReadOnly="True" SortExpression="emp_id">
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                </asp:BoundField>
                <asp:BoundField DataField="fname" HeaderText="First Name" SortExpression="fname">
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                </asp:BoundField>
                <asp:BoundField DataField="lname" HeaderText="Last Name" SortExpression="lname">
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                </asp:BoundField>
                <asp:BoundField DataField="dob" HeaderText="DOB" SortExpression="dob">
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                </asp:BoundField>
                <asp:BoundField DataField="hp_no" HeaderText="Handphone No" SortExpression="hp_no">
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                </asp:BoundField>
                <asp:BoundField DataField="address" HeaderText="Address" SortExpression="address">
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                </asp:BoundField>
                <asp:BoundField DataField="email" HeaderText="Email" SortExpression="email">
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                </asp:BoundField>
                <asp:BoundField DataField="bank_acc" HeaderText="Bank Account No" SortExpression="bank_acc">
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                </asp:BoundField>
                <asp:BoundField DataField="nationality" HeaderText="Nationality" SortExpression="nationality">
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                </asp:BoundField>
                <asp:BoundField DataField="when_joined" HeaderText="Joined Date" SortExpression="when_joined">
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                </asp:BoundField>
                <asp:BoundField DataField="role" HeaderText="Role" SortExpression="role">
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                </asp:BoundField>
                <asp:TemplateField HeaderText="Select" ShowHeader="False">
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Select" Text="Select"></asp:LinkButton>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                </asp:TemplateField>
                  <asp:TemplateField>
            <ItemTemplate> 
                <asp:HiddenField ID="HiddenField1" runat="server" 
                    Value='<%#Eval("password")%>'/>
            </ItemTemplate>
          </asp:TemplateField>
            </Columns>

            <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />

            <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF"></HeaderStyle>

            <PagerStyle ForeColor="#003399" HorizontalAlign="Left" BackColor="#99CCCC" />
            <RowStyle BackColor="White" ForeColor="#003399" />
            <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
            <SortedAscendingCellStyle BackColor="#EDF6F6" />
            <SortedAscendingHeaderStyle BackColor="#0D4AC4" />
            <SortedDescendingCellStyle BackColor="#D6DFDF" />
            <SortedDescendingHeaderStyle BackColor="#002876" />

        </asp:GridView>
    </div>
    <table style="width: 99%; margin-bottom: 0px; height: 235px; margin-top: 77px; border-color: black; border-style: solid">
        <tr>
            <td class="auto-style13">
                <asp:Label ID="lblUserID" runat="server" Text="User ID:"></asp:Label>
            </td>
            <td class="auto-style15">
                <asp:TextBox ID="txtUserID" runat="server" Width="203px"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*Required Field" ForeColor="Red" ControlToValidate="txtUserID"></asp:RequiredFieldValidator>
            </td>

            <td class="auto-style12">
                <asp:Label ID="lblHpno" runat="server" Text="Handphone No:"></asp:Label>
            </td>
            <td class="auto-style17">
                <asp:TextBox ID="txtHP" runat="server" Width="203px"></asp:TextBox>
            </td>
            <td class="auto-style18"></td>
            <td class="auto-style21">
                <asp:Label ID="Label4" runat="server" Text="Photo Name:"></asp:Label></td>
            <td>
                <asp:TextBox ID="txtpname" runat="server"></asp:TextBox></td>
            <td class="auto-style16" rowspan="5">


                <br />
                <br />
                <br />

                <br />

            </td>

        </tr>
        <tr>
            <td class="auto-style13">
                <asp:Label ID="lblPassword" runat="server" Text="New Password:"></asp:Label>
            </td>
            <td class="auto-style15">
                <asp:TextBox ID="txtPassword" runat="server" Width="203px" TextMode="Password"></asp:TextBox>
            </td>
            <td class="auto-style12">
                <asp:Label ID="lblAddr" runat="server" Text="Address:"></asp:Label>
            </td>
            <td class="auto-style17">
                <asp:TextBox ID="txtAddr" runat="server" Width="203px"></asp:TextBox>
            </td>
            <td class="auto-style18"></td>
            <td colspan="2" rowspan="4">
                <asp:Image ID="Image1" runat="server" Height="221px" Width="241px" Style="margin-left: 0px" />
                <br />
                <br />
                <asp:FileUpload ID="FileUpload1" runat="server" />

                <br />
                <asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click" Text="Upload" CausesValidation="False" Width="81px" />

                &nbsp;&nbsp;
    <asp:Button ID="lblCancelPic" runat="server" Text="Cancel" OnClick="lblCancelPic_Click" CausesValidation="False" />

            </td>
        </tr>
        <tr>
            <td class="auto-style13">
                <asp:Label ID="lblEmployeeID" runat="server" Text="Employee ID:"></asp:Label>
            </td>
            <td class="auto-style15">
                <asp:Label ID="lblShowEmpID" runat="server"></asp:Label>
            </td>
            <td class="auto-style12">
                <asp:Label ID="lblEmail" runat="server" Text="Email:"></asp:Label>
            </td>
            <td class="auto-style17">
                <asp:TextBox ID="txtEmail" runat="server" Width="203px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="auto-style13">
                <asp:Label ID="lblFname" runat="server" Text="First Name:"></asp:Label>
            </td>
            <td class="auto-style15">
                <asp:TextBox ID="txtFname" runat="server" Width="203px"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="*Required Field" ForeColor="Red" ControlToValidate="txtFname"></asp:RequiredFieldValidator>
            </td>
            <td class="auto-style12">
                <asp:Label ID="lblBankAcc" runat="server" Text="Bank Account No:"></asp:Label>
            </td>
            <td class="auto-style17">
                <asp:TextBox ID="txtBankAcc" runat="server" Width="203px"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td class="auto-style13">
                <asp:Label ID="lblLname" runat="server" Text="Last Name:"></asp:Label>
            </td>
            <td class="auto-style15">
                <asp:TextBox ID="txtLname" runat="server" Width="203px"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="*Required Field" ForeColor="Red" ControlToValidate="txtLname"></asp:RequiredFieldValidator>
            </td>
            <td class="auto-style12">
                <asp:Label ID="lblNationality" runat="server" Text="Nationality:"></asp:Label>
            </td>
            <td class="auto-style17">
                <asp:DropDownList ID="ddlNationality" runat="server" Width="208px" AppendDataBoundItems="true" AutoPostBack="False">
                    <asp:ListItem Text="Please Select" Value="" />
                    <asp:ListItem>Singaporean</asp:ListItem>
                    <asp:ListItem>Malaysian</asp:ListItem>
                    <asp:ListItem>Taiwanese</asp:ListItem>
                    <asp:ListItem>Chinese</asp:ListItem>
                    <asp:ListItem>Vietnamese</asp:ListItem>
                    <asp:ListItem>Thai</asp:ListItem>
                    <asp:ListItem>African</asp:ListItem>
                    <asp:ListItem>American</asp:ListItem>
                    <asp:ListItem>Swiss</asp:ListItem>
                    <asp:ListItem>French</asp:ListItem>
                    <asp:ListItem>Italian</asp:ListItem>
                </asp:DropDownList>
            </td>

        </tr>
        <tr>
            <td class="auto-style23">
                <asp:Label ID="lblRole" runat="server" Text="Role:"></asp:Label>
            </td>
            <td class="auto-style20">
                <asp:DropDownList ID="ddlRoles" runat="server" Width="208px" DataSourceID="SqlDataSource1_roles" DataTextField="role" DataValueField="role" AppendDataBoundItems="True">
                    <asp:ListItem Text="Please Select" Value="" />
                </asp:DropDownList>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ErrorMessage="*Required Field" ForeColor="Red" ControlToValidate="ddlRoles"></asp:RequiredFieldValidator>
            </td>
            <td class="auto-style19"></td>
            <td class="auto-style22"></td>

        </tr>
        <tr>
            <td class="auto-style13">
                <asp:Label ID="lblDob" runat="server" Text="DOB:"></asp:Label>

            </td>
            <td class="auto-style15">
                <asp:TextBox ID="txtDOB" runat="server" Width="165px"></asp:TextBox>
                <asp:Button ID="btnShowDOB" runat="server" Text="..." OnClick="btnShowDOB_Click" CausesValidation="False" />
                <asp:Calendar ID="calendar" runat="server" Width="220px" BackColor="White" BorderColor="#3366CC" BorderWidth="1px" CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="#003399" Height="200px" OnSelectionChanged="calendar_SelectionChanged" Visible="False">
                    <DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" />
                    <NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" />
                    <OtherMonthDayStyle ForeColor="#999999" />
                    <SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                    <SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
                    <TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px" Font-Bold="True" Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" />
                    <TodayDayStyle BackColor="#99CCCC" ForeColor="White" />
                    <WeekendDayStyle BackColor="#CCCCFF" />
                </asp:Calendar>
            </td>
            <td>
                <asp:Label ID="lblJoinDate" runat="server" Text="Joined Date:" Style="text-align: left"></asp:Label>



            </td>

            <td class="auto-style17">
                <asp:TextBox ID="txtJDate" runat="server" Width="167px"></asp:TextBox>
                <asp:Button ID="btnShowJDate" runat="server" Text="..." OnClick="btnShowJDate_Click" CausesValidation="False" />
                <asp:Calendar ID="calJoinDate" runat="server" Width="220px" BackColor="White" BorderColor="#3366CC" BorderWidth="1px" CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="#003399" Height="200px" OnSelectionChanged="calJoinDate_SelectionChanged" Visible="False">
                    <DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" />
                    <NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" />
                    <OtherMonthDayStyle ForeColor="#999999" />
                    <SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
                    <SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
                    <TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px" Font-Bold="True" Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" />
                    <TodayDayStyle BackColor="#99CCCC" ForeColor="White" />
                    <WeekendDayStyle BackColor="#CCCCFF" />
                </asp:Calendar>
            </td>
        </tr>
    </table>
    <br />
<br />
    <asp:Button ID="lblUpdate" runat="server" Text="Update Record" OnClick="lblUpdate_Click" />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Button ID="btnDelete" runat="server" BackColor="Red" ForeColor="Black" OnClick="btnDelete_Click" Text="Delete" Width="130px" />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Button ID="lblCancel" runat="server" Text="Cancel" OnClick="lblCancel_Click" CausesValidation="False" Width="90px" />
    <p>



        <asp:SqlDataSource ID="EMP_Records" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [Emp_records] WHERE [emp_id] = @original_emp_id AND [id_no] = @original_id_no AND (([fname] = @original_fname) OR ([fname] IS NULL AND @original_fname IS NULL)) AND (([lname] = @original_lname) OR ([lname] IS NULL AND @original_lname IS NULL)) AND (([dob] = @original_dob) OR ([dob] IS NULL AND @original_dob IS NULL)) AND (([hp_no] = @original_hp_no) OR ([hp_no] IS NULL AND @original_hp_no IS NULL)) AND (([address] = @original_address) OR ([address] IS NULL AND @original_address IS NULL)) AND (([email] = @original_email) OR ([email] IS NULL AND @original_email IS NULL)) AND (([bank_acc] = @original_bank_acc) OR ([bank_acc] IS NULL AND @original_bank_acc IS NULL)) AND (([nationality] = @original_nationality) OR ([nationality] IS NULL AND @original_nationality IS NULL)) AND (([when_joined] = @original_when_joined) OR ([when_joined] IS NULL AND @original_when_joined IS NULL)) AND (([p_id] = @original_p_id) OR ([p_id] IS NULL AND @original_p_id IS NULL))" InsertCommand="INSERT INTO [Emp_records] ([id_no], [emp_id], [fname], [lname], [dob], [hp_no], [address], [email], [bank_acc], [nationality], [when_joined], [p_id]) VALUES (@id_no, @emp_id, @fname, @lname, @dob, @hp_no, @address, @email, @bank_acc, @nationality, @when_joined, @p_id)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT e.id_no, e.emp_id, e.fname, e.lname, e.dob, e.hp_no, e.address, e.email, e.bank_acc, e.nationality, e.when_joined, u.u_id, u.role, u.password FROM Emp_records AS e INNER JOIN Users AS u ON e.emp_id = u.emp_id" UpdateCommand="UPDATE [Emp_records] SET [id_no] = @id_no, [fname] = @fname, [lname] = @lname, [dob] = @dob, [hp_no] = @hp_no, [address] = @address, [email] = @email, [bank_acc] = @bank_acc, [nationality] = @nationality, [when_joined] = @when_joined, [p_id] = @p_id WHERE [emp_id] = @original_emp_id AND [id_no] = @original_id_no AND (([fname] = @original_fname) OR ([fname] IS NULL AND @original_fname IS NULL)) AND (([lname] = @original_lname) OR ([lname] IS NULL AND @original_lname IS NULL)) AND (([dob] = @original_dob) OR ([dob] IS NULL AND @original_dob IS NULL)) AND (([hp_no] = @original_hp_no) OR ([hp_no] IS NULL AND @original_hp_no IS NULL)) AND (([address] = @original_address) OR ([address] IS NULL AND @original_address IS NULL)) AND (([email] = @original_email) OR ([email] IS NULL AND @original_email IS NULL)) AND (([bank_acc] = @original_bank_acc) OR ([bank_acc] IS NULL AND @original_bank_acc IS NULL)) AND (([nationality] = @original_nationality) OR ([nationality] IS NULL AND @original_nationality IS NULL)) AND (([when_joined] = @original_when_joined) OR ([when_joined] IS NULL AND @original_when_joined IS NULL)) AND (([p_id] = @original_p_id) OR ([p_id] IS NULL AND @original_p_id IS NULL))">
            <DeleteParameters>
                <asp:Parameter Name="original_emp_id" Type="String" />
                <asp:Parameter Name="original_id_no" Type="Int32" />
                <asp:Parameter Name="original_fname" Type="String" />
                <asp:Parameter Name="original_lname" Type="String" />
                <asp:Parameter DbType="Date" Name="original_dob" />
                <asp:Parameter Name="original_hp_no" Type="Decimal" />
                <asp:Parameter Name="original_address" Type="String" />
                <asp:Parameter Name="original_email" Type="String" />
                <asp:Parameter Name="original_bank_acc" Type="String" />
                <asp:Parameter Name="original_nationality" Type="String" />
                <asp:Parameter DbType="Date" Name="original_when_joined" />
                <asp:Parameter Name="original_p_id" Type="Int32" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="id_no" Type="Int32" />
                <asp:Parameter Name="emp_id" Type="String" />
                <asp:Parameter Name="fname" Type="String" />
                <asp:Parameter Name="lname" Type="String" />
                <asp:Parameter DbType="Date" Name="dob" />
                <asp:Parameter Name="hp_no" Type="Decimal" />
                <asp:Parameter Name="address" Type="String" />
                <asp:Parameter Name="email" Type="String" />
                <asp:Parameter Name="bank_acc" Type="String" />
                <asp:Parameter Name="nationality" Type="String" />
                <asp:Parameter DbType="Date" Name="when_joined" />
                <asp:Parameter Name="p_id" Type="Int32" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="id_no" Type="Int32" />
                <asp:Parameter Name="fname" Type="String" />
                <asp:Parameter Name="lname" Type="String" />
                <asp:Parameter DbType="Date" Name="dob" />
                <asp:Parameter Name="hp_no" Type="Decimal" />
                <asp:Parameter Name="address" Type="String" />
                <asp:Parameter Name="email" Type="String" />
                <asp:Parameter Name="bank_acc" Type="String" />
                <asp:Parameter Name="nationality" Type="String" />
                <asp:Parameter DbType="Date" Name="when_joined" />
                <asp:Parameter Name="p_id" Type="Int32" />
                <asp:Parameter Name="original_emp_id" Type="String" />
                <asp:Parameter Name="original_id_no" Type="Int32" />
                <asp:Parameter Name="original_fname" Type="String" />
                <asp:Parameter Name="original_lname" Type="String" />
                <asp:Parameter DbType="Date" Name="original_dob" />
                <asp:Parameter Name="original_hp_no" Type="Decimal" />
                <asp:Parameter Name="original_address" Type="String" />
                <asp:Parameter Name="original_email" Type="String" />
                <asp:Parameter Name="original_bank_acc" Type="String" />
                <asp:Parameter Name="original_nationality" Type="String" />
                <asp:Parameter DbType="Date" Name="original_when_joined" />
                <asp:Parameter Name="original_p_id" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource1_roles" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [role] FROM [Roles]"></asp:SqlDataSource>
    </p>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
    <link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/start/jquery-ui.css"
        rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        function ShowPopup(message) {
            $(function () {
                $("#dialog").html(message);
                $("#dialog").dialog({
                    title: "Warning!",
                    buttons: {
                        Close: function () {
                            $(this).dialog('close');
                        }
                    },
                    modal: true
                });
            });
        };
    </script>
    <div id="dialog" style="display: none">
    </div>
</asp:Content>

